/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.payment.web.controller;

import com.medusa.gruul.common.core.auth.client.helper.ISecurity;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.common.log.annotation.SysLog;
import com.medusa.gruul.payment.api.entity.MerchantDetails;
import com.medusa.gruul.payment.api.model.dto.MerchantDTO;
import com.medusa.gruul.payment.service.MultiMerchantService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 张治保
 * date 2021/12/18
 */
@RestController
@RequestMapping("/multi/merchant")
@RequiredArgsConstructor
public class MultiMerchantController {

    private final MultiMerchantService multiMerchantService;

    @SysLog("获取商户配置列表")
    @GetMapping
    public Result<List<MerchantDetails>> details(){
        return Result.ok(
            multiMerchantService.merchants(ISecurity.tenantId().must())
        );
    }

    @SysLog("新增/修改商户配置")
    @PostMapping
    public Result<Void> aliMerchant(@RequestBody @Validated MerchantDTO alipayMerchant){
        multiMerchantService.merchant(alipayMerchant);
        return Result.ok();
    }

    @SysLog("上传支付证书")
    @PostMapping("/wechat/upload/cert")
    public Result<String> uploadCertificate(@RequestParam("file") MultipartFile file) {
        return Result.ok(
            multiMerchantService.uploadCertificate(file)
        );
    }
}
